<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>上传文件</title>
        <style>
            *{
            margin: 0;
            padding: 0;
        }
        .head-btn{
            text-align: center;
            margin-top: 50px;
        }
        .file {
            position: relative;
            display: inline-block;
            background: rgb(0, 180, 255);
            border: 1px solid #99D3F5;
            border-radius: 10px;
            padding: 24px 50px;
            overflow: hidden;
            color: #FFFFFF;
            text-decoration: none;
            text-indent: 0;
            line-height: 20px;
            font-size: 40px;
        }
        .file input {
            position: absolute;
            font-size: 200px;
            right: 0;
            top: 0;
            opacity: 0;
        }
        .file:hover {
            background: #AADFFD;
            border-color: #78C3F3;
            color: #004974;
            text-decoration: none;
        }
        .determine{
            color: #FFFFFF;
            background-color: #007AFF;
            display: inline-block;
            font-size: 20px;
            border-radius: 5px;
            padding: 8px 24px;
        }
        .showFileName{
            display: inline-block;
            height: 30px;
            min-width: 300px;
        }
        .btn {
            display: block;
            margin: 20px auto;
            padding: 5px;
            background-color:rgb(0, 180, 255);
            border: 0;
            color: #333333;
            height: 40px;
            width: 200px;
            border-radius: 5px;
        }
        .btn1 {
            display: block;
            margin: 20px auto;
            padding: 5px;
            background-color: rgb(0, 180, 255);
            border: 0;
            color: #333333;
            height: 40px;
            width: 200px;
            border-radius: 5px;
        }
        
        .btn-red {
            background-color: #dd524d;
        }
        
        .btn-yellow {
            background-color: rgb(0, 180, 255);
        }
        
        .desc {
            padding: 10px;
            color: #999999;
        }
    </style>
    </head>
    <body>
        <div class="head-btn">
            <form action="" method="post">
                <a href="javascript:;" class="file">选择文件
                    <input type="file" accept=".pdf,.doc" name="uploadFile" id="uploadFile" >
                </a>
            </form>
            <p class="showFileName"></p>
        </div>
        <div>
            <button class="btn" type="button" data-action="redirectTo">确定</button>
            <button class="btn1" type="button" data-action="navigateBack">取消上传</button>
        </div>
        
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.js"></script>
        <script src="https://res.wx.qq.com/open/js/jweixin-1.3.0.js"></script>
        <script type="text/javascript" src="https://js.cdn.aliyun.dcloud.net.cn/dev/uni-app/uni.webview.1.5.2.js"></script>
        <script>
			var wenjiandata
            $(".file").on("change", "input[type='file']", function() {
                let filePath = $(this).val();
                localStorage.setItem("fileAddress", filePath);
                let lastname = localStorage.getItem("fileAddress");
				console.log(lastname)
				wenjiandata = lastname
                if (lastname != "") {
                    $(".showFileName").html(lastname);
                } else {
                    $(".showFileName").html("");
                }
            });

            $('.btn').click(function(evt) {
                var formdata = new FormData(); // 创建一个form类型的数据
                formdata.append("file",$("#uploadFile")[0].files[0]); // 获取上传文件的数据
				
                $.ajax({
                    url: 'https://admin2.2855855.com/front/common/upload',
                    type: "POST",
                    processData: false,
                    contentType: false,
                    data:formdata,
                    success: function(data) {
    					 var target = evt.target;
                        if (target.tagName === 'BUTTON') {
                            var action = target.getAttribute('data-action');
                            if (action == 'redirectTo') {
                                     uni.redirectTo({
                                        url: '/pagesSecond/strategy/strategyRelease?res='+ data.url,
                                        success:function (d) {
                                            console.log("跳转成功");
                                        },
                                    });
                                //  wx.miniProgram.redirectTo({
                                //     url: '/pages/ke/writePlan?res='+ JSON.stringify(data.res),
                                //     success:function (d) {
                                //         console.log("跳转成功");
                                //     },
                                //     fail:function(e){
                                //         console.log(e);
                                //     },
                                // });
                            }
                        }
                    },
                    error: function(err) {
                        console.log("这是请求失败的");
                    }
                });

               
            });
            
            //取消文件上传
            $('.btn1').click(function(evt) {
                var target = evt.target;
                if (target.tagName === 'BUTTON') {
                    var action = target.getAttribute('data-action');
                    if (action == 'navigateBack') {
                        uni.navigateBack({
                            delta: 1
                        });
                    }
                }
            });
            
            
        </script>
    </body>
</html>